• Main Page
  • Classes
  • Files
  • File List
  • File Members

C:/Programming/CodeLite/Codes/LibGL2D/gl2d.c

00001 /*
00002 
00003         Easy GL2D
00004 
00005         Relminator 2010
00006         Richard Eric M. Lope BSN RN
00007 
00008         http://rel.phatcode.net
00009 
00010 
00011 */
00012 
00013 
00014 #include "gl2d.h"
00015 
00016 // mingw header excluding GL_BGRA in windows
00017 #ifndef GL_BGRA
00018 #define GL_BGRA  0x80E1
00019 #endif
00020 
00021 static GLuint gCurrentTexture = 0;
00022 static GLuint gFontOffset = 0;
00023 static GLuint gGlowTexture = 0;
00024 /******************************************************************************
00025 
00026     IMPLEMENTATION
00027 
00028 ******************************************************************************/
00029 
00030 
00031 /******************************************************************************
00032 
00033    Private!!!
00034    Abstracted(to be)  LoadTexture function
00035 
00036 ******************************************************************************/
00037 
00038 int LoadTexture( const char *filename )
00039 {
00040 
00041     if ( !glfwLoadTexture2D( filename, GLFW_BUILD_MIPMAPS_BIT | GLFW_ORIGIN_UL_BIT) )
00042     {
00043         glfwTerminate();
00044         printf( "Error loading %s", filename );
00045         return false;
00046     }
00047 
00048 
00049     return true;
00050 
00051 }
00052 
00053 
00054 
00055 /******************************************************************************
00056 
00057    Public funks
00058    
00059 ******************************************************************************/
00060 
00061 void glBegin2D( const int width, const int height )
00062 {
00063 
00064     gCurrentTexture = 0;
00065     glDisable( GL_DEPTH_TEST );
00066     glDisable( GL_CULL_FACE);
00067 
00068     glEnable( GL_BLEND );
00069     glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
00070 
00071     glEnable( GL_ALPHA_TEST );
00072     glAlphaFunc( GL_GREATER, 0 );
00073 
00074     glPolygonMode( GL_FRONT, GL_FILL );
00075 
00076         glEnable( GL_COLOR_MATERIAL );
00077         glEnable( GL_TEXTURE_2D );
00078         
00079     glDisable( GL_STENCIL_TEST );
00080     glDisable( GL_TEXTURE_1D );
00081     glDisable( GL_LIGHTING );
00082     glDisable( GL_LOGIC_OP );
00083     glDisable( GL_DITHER );
00084     glDisable( GL_FOG );
00085 
00086     glPointSize( 1.0 );
00087     glLineWidth( 1.0 );
00088         
00089     glHint( GL_POINT_SMOOTH_HINT, GL_NICEST );
00090     glHint( GL_LINE_SMOOTH_HINT , GL_NICEST );
00091 
00092     glMatrixMode( GL_PROJECTION );
00093     glPushMatrix();
00094     glLoadIdentity();
00095     glOrtho( 0, width, height, 0, -1, 1 );
00096     glMatrixMode( GL_MODELVIEW );
00097     glPushMatrix();
00098     glLoadIdentity();
00099     glTranslatef( 0.375, 0.375, 0.0 );
00100 
00101 }
00102 
00103 void glEnd2D()
00104 {
00105 
00106     glMatrixMode( GL_PROJECTION );
00107     glPopMatrix();
00108     glMatrixMode( GL_MODELVIEW );
00109     glPopMatrix();
00110     
00111     glBlendMode( GL2D_SOLID );
00112     glColor4ub(255,255,255,255);
00113         
00114 }
00115 
00116 
00117 
00118 
00119 /******************************************************************************
00120 
00121     Sets texture environment color
00122     
00123     (1 - (texture image color))*(glColor colour) + (texture image colour)*(texture environment colour)
00124     I didn't put this as part of the set_blend since we can use this alongside
00125     blending
00126 
00127 ******************************************************************************/
00128 
00129 void glEnableSpriteStencil( const GLuint gl2dcolor, const GLuint gl2dcolor_env, int flag )
00130 {
00131                 
00132         static GLfloat env_color[3];
00133         if( flag )
00134         {       
00135                 env_color[0] = ARGB_B(gl2dcolor_env)/255.0f;
00136                 env_color[1] = ARGB_G(gl2dcolor_env)/255.0f;
00137                 env_color[2] = ARGB_R(gl2dcolor_env)/255.0f;
00138                 env_color[3] = ARGB_A(gl2dcolor_env)/255.0f;
00139                 
00140                 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND);
00141                 glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, &env_color[0]);
00142                 glColor4ubv( (GLubyte*)&gl2dcolor );    
00143         }
00144         else
00145         {
00146                 glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
00147         }
00148         
00149 }
00150 
00151 /******************************************************************************
00152 
00153     Enables or disables AA depending on the switch
00154           
00155 ******************************************************************************/
00156 
00157 void glEnableAntialias( int flag )
00158 {       
00159         if( flag )
00160         {
00161                 glEnable( GL_POINT_SMOOTH );
00162         glEnable( GL_LINE_SMOOTH  );
00163         }
00164         else
00165         {
00166                 glDisable( GL_POINT_SMOOTH );
00167         glDisable( GL_LINE_SMOOTH  );
00168         }
00169         
00170 }
00171 
00172 /******************************************************************************
00173 
00174 
00175 ******************************************************************************/
00176 GLuint GetGlowImage()
00177 {
00178 
00179     if ( gGlowTexture == 0 )
00180         {
00181         const int IMAGE_WIDTH = 32, IMAGE_HEIGHT = 32;
00182 
00183                 const unsigned int image_array[] = {
00184             0x00000007, 0x00000004, 0x00000020, 0x00000020, 0x00000080, 0x00000000,
00185             0x00000000, 0x00000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000,
00186             0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000,
00187             0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000,
00188             0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000,
00189             0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000,
00190             0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000,
00191             0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000,
00192             0xFF000000, 0xFF000000, 0xFF000000, 0xFF010101, 0xFF010101, 0xFF020202,
00193             0xFF020202, 0xFF030303, 0xFF030303, 0xFF030303, 0xFF020202, 0xFF020202,
00194             0xFF010101, 0xFF010101, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000,
00195             0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000,
00196             0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000,
00197             0xFF000000, 0xFF000000, 0xFF000000, 0xFF010101, 0xFF020202, 0xFF030303,
00198             0xFF040404, 0xFF050505, 0xFF060606, 0xFF060606, 0xFF060606, 0xFF060606,
00199             0xFF060606, 0xFF050505, 0xFF040404, 0xFF030303, 0xFF020202, 0xFF010101,
00200             0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000,
00201             0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000,
00202             0xFF000000, 0xFF000000, 0xFF000000, 0xFF010101, 0xFF020202, 0xFF040404,
00203             0xFF050505, 0xFF070707, 0xFF080808, 0xFF090909, 0xFF0A0A0A, 0xFF0B0B0B,
00204             0xFF0B0B0B, 0xFF0B0B0B, 0xFF0A0A0A, 0xFF090909, 0xFF080808, 0xFF070707,
00205             0xFF050505, 0xFF040404, 0xFF020202, 0xFF010101, 0xFF000000, 0xFF000000,
00206             0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000,
00207             0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF010101, 0xFF030303,
00208             0xFF050505, 0xFF070707, 0xFF090909, 0xFF0B0B0B, 0xFF0C0C0C, 0xFF0E0E0E,
00209             0xFF0F0F0F, 0xFF0F0F0F, 0xFF101010, 0xFF0F0F0F, 0xFF0F0F0F, 0xFF0E0E0E,
00210             0xFF0C0C0C, 0xFF0B0B0B, 0xFF090909, 0xFF070707, 0xFF050505, 0xFF030303,
00211             0xFF010101, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000,
00212             0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF010101,
00213             0xFF030303, 0xFF060606, 0xFF080808, 0xFF0B0B0B, 0xFF0D0D0D, 0xFF0F0F0F,
00214             0xFF111111, 0xFF131313, 0xFF141414, 0xFF151515, 0xFF151515, 0xFF151515,
00215             0xFF141414, 0xFF131313, 0xFF111111, 0xFF0F0F0F, 0xFF0D0D0D, 0xFF0B0B0B,
00216             0xFF080808, 0xFF060606, 0xFF030303, 0xFF010101, 0xFF000000, 0xFF000000,
00217             0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000,
00218             0xFF010101, 0xFF030303, 0xFF060606, 0xFF090909, 0xFF0C0C0C, 0xFF0E0E0E,
00219             0xFF121212, 0xFF141414, 0xFF161616, 0xFF181818, 0xFF191919, 0xFF1A1A1A,
00220             0xFF1B1B1B, 0xFF1A1A1A, 0xFF191919, 0xFF181818, 0xFF161616, 0xFF141414,
00221             0xFF121212, 0xFF0E0E0E, 0xFF0C0C0C, 0xFF090909, 0xFF060606, 0xFF030303,
00222             0xFF010101, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000,
00223             0xFF000000, 0xFF010101, 0xFF030303, 0xFF060606, 0xFF090909, 0xFF0C0C0C,
00224             0xFF0F0F0F, 0xFF131313, 0xFF161616, 0xFF191919, 0xFF1B1B1B, 0xFF1E1E1E,
00225             0xFF1F1F1F, 0xFF202020, 0xFF212121, 0xFF202020, 0xFF1F1F1F, 0xFF1E1E1E,
00226             0xFF1B1B1B, 0xFF191919, 0xFF161616, 0xFF131313, 0xFF0F0F0F, 0xFF0C0C0C,
00227             0xFF090909, 0xFF060606, 0xFF030303, 0xFF010101, 0xFF000000, 0xFF000000,
00228             0xFF000000, 0xFF000000, 0xFF000000, 0xFF020202, 0xFF050505, 0xFF080808,
00229             0xFF0C0C0C, 0xFF0F0F0F, 0xFF131313, 0xFF171717, 0xFF1B1B1B, 0xFF1E1E1E,
00230             0xFF212121, 0xFF232323, 0xFF252525, 0xFF262626, 0xFF272727, 0xFF262626,
00231             0xFF252525, 0xFF232323, 0xFF212121, 0xFF1E1E1E, 0xFF1B1B1B, 0xFF171717,
00232             0xFF131313, 0xFF0F0F0F, 0xFF0C0C0C, 0xFF080808, 0xFF050505, 0xFF020202,
00233             0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF010101, 0xFF040404,
00234             0xFF070707, 0xFF0B0B0B, 0xFF0E0E0E, 0xFF131313, 0xFF171717, 0xFF1B1B1B,
00235             0xFF1F1F1F, 0xFF232323, 0xFF262626, 0xFF292929, 0xFF2B2B2B, 0xFF2C2C2C,
00236             0xFF2C2C2C, 0xFF2C2C2C, 0xFF2B2B2B, 0xFF292929, 0xFF262626, 0xFF232323,
00237             0xFF1F1F1F, 0xFF1B1B1B, 0xFF171717, 0xFF131313, 0xFF0E0E0E, 0xFF0B0B0B,
00238             0xFF070707, 0xFF040404, 0xFF010101, 0xFF000000, 0xFF000000, 0xFF000000,
00239             0xFF020202, 0xFF050505, 0xFF090909, 0xFF0D0D0D, 0xFF121212, 0xFF161616,
00240             0xFF1B1B1B, 0xFF1F1F1F, 0xFF242424, 0xFF282828, 0xFF2B2B2B, 0xFF2E2E2E,
00241             0xFF313131, 0xFF323232, 0xFF323232, 0xFF323232, 0xFF313131, 0xFF2E2E2E,
00242             0xFF2B2B2B, 0xFF282828, 0xFF242424, 0xFF1F1F1F, 0xFF1B1B1B, 0xFF161616,
00243             0xFF121212, 0xFF0D0D0D, 0xFF090909, 0xFF050505, 0xFF020202, 0xFF000000,
00244             0xFF000000, 0xFF010101, 0xFF030303, 0xFF070707, 0xFF0B0B0B, 0xFF0F0F0F,
00245             0xFF141414, 0xFF191919, 0xFF1E1E1E, 0xFF232323, 0xFF282828, 0xFF2C2C2C,
00246             0xFF303030, 0xFF333333, 0xFF363636, 0xFF383838, 0xFF383838, 0xFF383838,
00247             0xFF363636, 0xFF333333, 0xFF303030, 0xFF2C2C2C, 0xFF282828, 0xFF232323,
00248             0xFF1E1E1E, 0xFF191919, 0xFF141414, 0xFF0F0F0F, 0xFF0B0B0B, 0xFF070707,
00249             0xFF030303, 0xFF010101, 0xFF000000, 0xFF010101, 0xFF040404, 0xFF080808,
00250             0xFF0C0C0C, 0xFF111111, 0xFF161616, 0xFF1B1B1B, 0xFF212121, 0xFF262626,
00251             0xFF2B2B2B, 0xFF303030, 0xFF343434, 0xFF383838, 0xFF3B3B3B, 0xFF3D3D3D,
00252             0xFF3D3D3D, 0xFF3D3D3D, 0xFF3B3B3B, 0xFF383838, 0xFF343434, 0xFF303030,
00253             0xFF2B2B2B, 0xFF262626, 0xFF212121, 0xFF1B1B1B, 0xFF161616, 0xFF111111,
00254             0xFF0C0C0C, 0xFF080808, 0xFF040404, 0xFF010101, 0xFF000000, 0xFF020202,
00255             0xFF050505, 0xFF090909, 0xFF0E0E0E, 0xFF131313, 0xFF181818, 0xFF1E1E1E,
00256             0xFF232323, 0xFF292929, 0xFF2E2E2E, 0xFF333333, 0xFF383838, 0xFF3C3C3C,
00257             0xFF3F3F3F, 0xFF424242, 0xFF424242, 0xFF424242, 0xFF3F3F3F, 0xFF3C3C3C,
00258             0xFF383838, 0xFF333333, 0xFF2E2E2E, 0xFF292929, 0xFF232323, 0xFF1E1E1E,
00259             0xFF181818, 0xFF131313, 0xFF0E0E0E, 0xFF090909, 0xFF050505, 0xFF020202,
00260             0xFF000000, 0xFF020202, 0xFF060606, 0xFF0A0A0A, 0xFF0F0F0F, 0xFF141414,
00261             0xFF191919, 0xFF1F1F1F, 0xFF252525, 0xFF2B2B2B, 0xFF313131, 0xFF363636,
00262             0xFF3B3B3B, 0xFF3F3F3F, 0xFF434343, 0xFF454545, 0xFF474747, 0xFF454545,
00263             0xFF434343, 0xFF3F3F3F, 0xFF3B3B3B, 0xFF363636, 0xFF313131, 0xFF2B2B2B,
00264             0xFF252525, 0xFF1F1F1F, 0xFF191919, 0xFF141414, 0xFF0F0F0F, 0xFF0A0A0A,
00265             0xFF060606, 0xFF020202, 0xFF000000, 0xFF030303, 0xFF060606, 0xFF0B0B0B,
00266             0xFF0F0F0F, 0xFF151515, 0xFF1A1A1A, 0xFF202020, 0xFF262626, 0xFF2C2C2C,
00267             0xFF323232, 0xFF383838, 0xFF3D3D3D, 0xFF424242, 0xFF454545, 0xFFAEAEAE,
00268             0xFFD3D3D3, 0xFF454545, 0xFF454545, 0xFF424242, 0xFF3D3D3D, 0xFF383838,
00269             0xFF323232, 0xFF2C2C2C, 0xFF262626, 0xFF202020, 0xFF1A1A1A, 0xFF151515,
00270             0xFF0F0F0F, 0xFF0B0B0B, 0xFF060606, 0xFF030303, 0xFF000000, 0xFF030303,
00271             0xFF060606, 0xFF0B0B0B, 0xFF101010, 0xFF151515, 0xFF1B1B1B, 0xFF212121,
00272             0xFF272727, 0xFF2C2C2C, 0xFF323232, 0xFF383838, 0xFF3D3D3D, 0xFF424242,
00273             0xFF474747, 0xFFD3D3D3, 0xFFFFFFFF, 0xFF454545, 0xFF474747, 0xFF424242,
00274             0xFF3D3D3D, 0xFF383838, 0xFF323232, 0xFF2C2C2C, 0xFF272727, 0xFF212121,
00275             0xFF1B1B1B, 0xFF151515, 0xFF101010, 0xFF0B0B0B, 0xFF060606, 0xFF030303,
00276             0xFF000000, 0xFF030303, 0xFF060606, 0xFF0B0B0B, 0xFF0F0F0F, 0xFF151515,
00277             0xFF1A1A1A, 0xFF202020, 0xFF262626, 0xFF2C2C2C, 0xFF323232, 0xFF383838,
00278             0xFF3D3D3D, 0xFF424242, 0xFF454545, 0xFF454545, 0xFF454545, 0xFF454545,
00279             0xFF454545, 0xFF424242, 0xFF3D3D3D, 0xFF383838, 0xFF323232, 0xFF2C2C2C,
00280             0xFF262626, 0xFF202020, 0xFF1A1A1A, 0xFF151515, 0xFF0F0F0F, 0xFF0B0B0B,
00281             0xFF060606, 0xFF030303, 0xFF000000, 0xFF020202, 0xFF060606, 0xFF0A0A0A,
00282             0xFF0F0F0F, 0xFF141414, 0xFF191919, 0xFF1F1F1F, 0xFF252525, 0xFF2B2B2B,
00283             0xFF313131, 0xFF363636, 0xFF3B3B3B, 0xFF3F3F3F, 0xFF434343, 0xFF454545,
00284             0xFF474747, 0xFF454545, 0xFF434343, 0xFF3F3F3F, 0xFF3B3B3B, 0xFF363636,
00285             0xFF313131, 0xFF2B2B2B, 0xFF252525, 0xFF1F1F1F, 0xFF191919, 0xFF141414,
00286             0xFF0F0F0F, 0xFF0A0A0A, 0xFF060606, 0xFF020202, 0xFF000000, 0xFF020202,
00287             0xFF050505, 0xFF090909, 0xFF0E0E0E, 0xFF131313, 0xFF181818, 0xFF1E1E1E,
00288             0xFF232323, 0xFF292929, 0xFF2E2E2E, 0xFF333333, 0xFF383838, 0xFF3C3C3C,
00289             0xFF3F3F3F, 0xFF424242, 0xFF424242, 0xFF424242, 0xFF3F3F3F, 0xFF3C3C3C,
00290             0xFF383838, 0xFF333333, 0xFF2E2E2E, 0xFF292929, 0xFF232323, 0xFF1E1E1E,
00291             0xFF181818, 0xFF131313, 0xFF0E0E0E, 0xFF090909, 0xFF050505, 0xFF020202,
00292             0xFF000000, 0xFF010101, 0xFF040404, 0xFF080808, 0xFF0C0C0C, 0xFF111111,
00293             0xFF161616, 0xFF1B1B1B, 0xFF212121, 0xFF262626, 0xFF2B2B2B, 0xFF303030,
00294             0xFF343434, 0xFF383838, 0xFF3B3B3B, 0xFF3D3D3D, 0xFF3D3D3D, 0xFF3D3D3D,
00295             0xFF3B3B3B, 0xFF383838, 0xFF343434, 0xFF303030, 0xFF2B2B2B, 0xFF262626,
00296             0xFF212121, 0xFF1B1B1B, 0xFF161616, 0xFF111111, 0xFF0C0C0C, 0xFF080808,
00297             0xFF040404, 0xFF010101, 0xFF000000, 0xFF010101, 0xFF030303, 0xFF070707,
00298             0xFF0B0B0B, 0xFF0F0F0F, 0xFF141414, 0xFF191919, 0xFF1E1E1E, 0xFF232323,
00299             0xFF282828, 0xFF2C2C2C, 0xFF303030, 0xFF333333, 0xFF363636, 0xFF383838,
00300             0xFF383838, 0xFF383838, 0xFF363636, 0xFF333333, 0xFF303030, 0xFF2C2C2C,
00301             0xFF282828, 0xFF232323, 0xFF1E1E1E, 0xFF191919, 0xFF141414, 0xFF0F0F0F,
00302             0xFF0B0B0B, 0xFF070707, 0xFF030303, 0xFF010101, 0xFF000000, 0xFF000000,
00303             0xFF020202, 0xFF050505, 0xFF090909, 0xFF0D0D0D, 0xFF121212, 0xFF161616,
00304             0xFF1B1B1B, 0xFF1F1F1F, 0xFF242424, 0xFF282828, 0xFF2B2B2B, 0xFF2E2E2E,
00305             0xFF313131, 0xFF323232, 0xFF323232, 0xFF323232, 0xFF313131, 0xFF2E2E2E,
00306             0xFF2B2B2B, 0xFF282828, 0xFF242424, 0xFF1F1F1F, 0xFF1B1B1B, 0xFF161616,
00307             0xFF121212, 0xFF0D0D0D, 0xFF090909, 0xFF050505, 0xFF020202, 0xFF000000,
00308             0xFF000000, 0xFF000000, 0xFF010101, 0xFF040404, 0xFF070707, 0xFF0B0B0B,
00309             0xFF0E0E0E, 0xFF131313, 0xFF171717, 0xFF1B1B1B, 0xFF1F1F1F, 0xFF232323,
00310             0xFF262626, 0xFF292929, 0xFF2B2B2B, 0xFF2C2C2C, 0xFF2C2C2C, 0xFF2C2C2C,
00311             0xFF2B2B2B, 0xFF292929, 0xFF262626, 0xFF232323, 0xFF1F1F1F, 0xFF1B1B1B,
00312             0xFF171717, 0xFF131313, 0xFF0E0E0E, 0xFF0B0B0B, 0xFF070707, 0xFF040404,
00313             0xFF010101, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF020202,
00314             0xFF050505, 0xFF080808, 0xFF0C0C0C, 0xFF0F0F0F, 0xFF131313, 0xFF171717,
00315             0xFF1B1B1B, 0xFF1E1E1E, 0xFF212121, 0xFF232323, 0xFF252525, 0xFF262626,
00316             0xFF272727, 0xFF262626, 0xFF252525, 0xFF232323, 0xFF212121, 0xFF1E1E1E,
00317             0xFF1B1B1B, 0xFF171717, 0xFF131313, 0xFF0F0F0F, 0xFF0C0C0C, 0xFF080808,
00318             0xFF050505, 0xFF020202, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000,
00319             0xFF000000, 0xFF010101, 0xFF030303, 0xFF060606, 0xFF090909, 0xFF0C0C0C,
00320             0xFF0F0F0F, 0xFF131313, 0xFF161616, 0xFF191919, 0xFF1B1B1B, 0xFF1E1E1E,
00321             0xFF1F1F1F, 0xFF202020, 0xFF212121, 0xFF202020, 0xFF1F1F1F, 0xFF1E1E1E,
00322             0xFF1B1B1B, 0xFF191919, 0xFF161616, 0xFF131313, 0xFF0F0F0F, 0xFF0C0C0C,
00323             0xFF090909, 0xFF060606, 0xFF030303, 0xFF010101, 0xFF000000, 0xFF000000,
00324             0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF010101, 0xFF030303,
00325             0xFF060606, 0xFF090909, 0xFF0C0C0C, 0xFF0E0E0E, 0xFF121212, 0xFF141414,
00326             0xFF161616, 0xFF181818, 0xFF191919, 0xFF1A1A1A, 0xFF1B1B1B, 0xFF1A1A1A,
00327             0xFF191919, 0xFF181818, 0xFF161616, 0xFF141414, 0xFF121212, 0xFF0E0E0E,
00328             0xFF0C0C0C, 0xFF090909, 0xFF060606, 0xFF030303, 0xFF010101, 0xFF000000,
00329             0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000,
00330             0xFF000000, 0xFF010101, 0xFF030303, 0xFF060606, 0xFF080808, 0xFF0B0B0B,
00331             0xFF0D0D0D, 0xFF0F0F0F, 0xFF111111, 0xFF131313, 0xFF141414, 0xFF151515,
00332             0xFF151515, 0xFF151515, 0xFF141414, 0xFF131313, 0xFF111111, 0xFF0F0F0F,
00333             0xFF0D0D0D, 0xFF0B0B0B, 0xFF080808, 0xFF060606, 0xFF030303, 0xFF010101,
00334             0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000,
00335             0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF010101, 0xFF030303,
00336             0xFF050505, 0xFF070707, 0xFF090909, 0xFF0B0B0B, 0xFF0C0C0C, 0xFF0E0E0E,
00337             0xFF0F0F0F, 0xFF0F0F0F, 0xFF101010, 0xFF0F0F0F, 0xFF0F0F0F, 0xFF0E0E0E,
00338             0xFF0C0C0C, 0xFF0B0B0B, 0xFF090909, 0xFF070707, 0xFF050505, 0xFF030303,
00339             0xFF010101, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000,
00340             0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000,
00341             0xFF000000, 0xFF010101, 0xFF020202, 0xFF040404, 0xFF050505, 0xFF070707,
00342             0xFF080808, 0xFF090909, 0xFF0A0A0A, 0xFF0B0B0B, 0xFF0B0B0B, 0xFF0B0B0B,
00343             0xFF0A0A0A, 0xFF090909, 0xFF080808, 0xFF070707, 0xFF050505, 0xFF040404,
00344             0xFF020202, 0xFF010101, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000,
00345             0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000,
00346             0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF010101,
00347             0xFF020202, 0xFF030303, 0xFF040404, 0xFF050505, 0xFF060606, 0xFF060606,
00348             0xFF060606, 0xFF060606, 0xFF060606, 0xFF050505, 0xFF040404, 0xFF030303,
00349             0xFF020202, 0xFF010101, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000,
00350             0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000,
00351             0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000,
00352             0xFF000000, 0xFF000000, 0xFF000000, 0xFF010101, 0xFF010101, 0xFF020202,
00353             0xFF020202, 0xFF030303, 0xFF030303, 0xFF030303, 0xFF020202, 0xFF020202,
00354             0xFF010101, 0xFF010101, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000,
00355             0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000 };
00356 
00357         glGenTextures( 1, &gGlowTexture );
00358         glBindTexture( GL_TEXTURE_2D, gGlowTexture );
00359 
00360         glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, IMAGE_WIDTH, IMAGE_HEIGHT,
00361                                   0, GL_BGRA, GL_UNSIGNED_BYTE, image_array + 8 );
00362 
00363         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
00364         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
00365         glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
00366         glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
00367         glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
00368 
00369         }
00370 
00371         return gGlowTexture;
00372 }
00373 
00374 
00375 /******************************************************************************
00376 
00377 
00378 ******************************************************************************/
00379 
00380 void FontInit()
00381 {
00382         const GLubyte rasterfont[95][13] = {
00383                 
00384                 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
00385                 {0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18},
00386                 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x36, 0x36, 0x36},
00387                 {0x00, 0x00, 0x00, 0x66, 0x66, 0xff, 0x66, 0x66, 0xff, 0x66, 0x66, 0x00, 0x00},
00388                 {0x00, 0x00, 0x18, 0x7e, 0xff, 0x1b, 0x1f, 0x7e, 0xf8, 0xd8, 0xff, 0x7e, 0x18},
00389                 {0x00, 0x00, 0x0e, 0x1b, 0xdb, 0x6e, 0x30, 0x18, 0x0c, 0x76, 0xdb, 0xd8, 0x70},
00390                 {0x00, 0x00, 0x7f, 0xc6, 0xcf, 0xd8, 0x70, 0x70, 0xd8, 0xcc, 0xcc, 0x6c, 0x38},
00391                 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x1c, 0x0c, 0x0e},
00392                 {0x00, 0x00, 0x0c, 0x18, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x18, 0x0c},
00393                 {0x00, 0x00, 0x30, 0x18, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x18, 0x30},
00394                 {0x00, 0x00, 0x00, 0x00, 0x99, 0x5a, 0x3c, 0xff, 0x3c, 0x5a, 0x99, 0x00, 0x00},
00395                 {0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0xff, 0xff, 0x18, 0x18, 0x18, 0x00, 0x00},
00396                 {0x00, 0x00, 0x30, 0x18, 0x1c, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
00397                 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00},
00398                 {0x00, 0x00, 0x00, 0x38, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
00399                 {0x00, 0x60, 0x60, 0x30, 0x30, 0x18, 0x18, 0x0c, 0x0c, 0x06, 0x06, 0x03, 0x03},
00400                 {0x00, 0x00, 0x3c, 0x66, 0xc3, 0xe3, 0xf3, 0xdb, 0xcf, 0xc7, 0xc3, 0x66, 0x3c},
00401                 {0x00, 0x00, 0x7e, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x78, 0x38, 0x18},
00402                 {0x00, 0x00, 0xff, 0xc0, 0xc0, 0x60, 0x30, 0x18, 0x0c, 0x06, 0x03, 0xe7, 0x7e},
00403                 {0x00, 0x00, 0x7e, 0xe7, 0x03, 0x03, 0x07, 0x7e, 0x07, 0x03, 0x03, 0xe7, 0x7e},
00404                 {0x00, 0x00, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0xff, 0xcc, 0x6c, 0x3c, 0x1c, 0x0c},
00405                 {0x00, 0x00, 0x7e, 0xe7, 0x03, 0x03, 0x07, 0xfe, 0xc0, 0xc0, 0xc0, 0xc0, 0xff},
00406                 {0x00, 0x00, 0x7e, 0xe7, 0xc3, 0xc3, 0xc7, 0xfe, 0xc0, 0xc0, 0xc0, 0xe7, 0x7e},
00407                 {0x00, 0x00, 0x30, 0x30, 0x30, 0x30, 0x18, 0x0c, 0x06, 0x03, 0x03, 0x03, 0xff},
00408                 {0x00, 0x00, 0x7e, 0xe7, 0xc3, 0xc3, 0xe7, 0x7e, 0xe7, 0xc3, 0xc3, 0xe7, 0x7e},
00409                 {0x00, 0x00, 0x7e, 0xe7, 0x03, 0x03, 0x03, 0x7f, 0xe7, 0xc3, 0xc3, 0xe7, 0x7e},
00410                 {0x00, 0x00, 0x00, 0x38, 0x38, 0x00, 0x00, 0x38, 0x38, 0x00, 0x00, 0x00, 0x00},
00411                 {0x00, 0x00, 0x30, 0x18, 0x1c, 0x1c, 0x00, 0x00, 0x1c, 0x1c, 0x00, 0x00, 0x00},
00412                 {0x00, 0x00, 0x06, 0x0c, 0x18, 0x30, 0x60, 0xc0, 0x60, 0x30, 0x18, 0x0c, 0x06},
00413                 {0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00},
00414                 {0x00, 0x00, 0x60, 0x30, 0x18, 0x0c, 0x06, 0x03, 0x06, 0x0c, 0x18, 0x30, 0x60},
00415                 {0x00, 0x00, 0x18, 0x00, 0x00, 0x18, 0x18, 0x0c, 0x06, 0x03, 0xc3, 0xc3, 0x7e},
00416                 {0x00, 0x00, 0x3f, 0x60, 0xcf, 0xdb, 0xd3, 0xdd, 0xc3, 0x7e, 0x00, 0x00, 0x00},
00417                 {0x00, 0x00, 0xc3, 0xc3, 0xc3, 0xc3, 0xff, 0xc3, 0xc3, 0xc3, 0x66, 0x3c, 0x18},
00418                 {0x00, 0x00, 0xfe, 0xc7, 0xc3, 0xc3, 0xc7, 0xfe, 0xc7, 0xc3, 0xc3, 0xc7, 0xfe},
00419                 {0x00, 0x00, 0x7e, 0xe7, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xe7, 0x7e},
00420                 {0x00, 0x00, 0xfc, 0xce, 0xc7, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc7, 0xce, 0xfc},
00421                 {0x00, 0x00, 0xff, 0xc0, 0xc0, 0xc0, 0xc0, 0xfc, 0xc0, 0xc0, 0xc0, 0xc0, 0xff},
00422                 {0x00, 0x00, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xfc, 0xc0, 0xc0, 0xc0, 0xff},
00423                 {0x00, 0x00, 0x7e, 0xe7, 0xc3, 0xc3, 0xcf, 0xc0, 0xc0, 0xc0, 0xc0, 0xe7, 0x7e},
00424                 {0x00, 0x00, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xff, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3},
00425                 {0x00, 0x00, 0x7e, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x7e},
00426                 {0x00, 0x00, 0x7c, 0xee, 0xc6, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06},
00427                 {0x00, 0x00, 0xc3, 0xc6, 0xcc, 0xd8, 0xf0, 0xe0, 0xf0, 0xd8, 0xcc, 0xc6, 0xc3},
00428                 {0x00, 0x00, 0xff, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0},
00429                 {0x00, 0x00, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xdb, 0xff, 0xff, 0xe7, 0xc3},
00430                 {0x00, 0x00, 0xc7, 0xc7, 0xcf, 0xcf, 0xdf, 0xdb, 0xfb, 0xf3, 0xf3, 0xe3, 0xe3},
00431                 {0x00, 0x00, 0x7e, 0xe7, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xe7, 0x7e},
00432                 {0x00, 0x00, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xfe, 0xc7, 0xc3, 0xc3, 0xc7, 0xfe},
00433                 {0x00, 0x00, 0x3f, 0x6e, 0xdf, 0xdb, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0x66, 0x3c},
00434                 {0x00, 0x00, 0xc3, 0xc6, 0xcc, 0xd8, 0xf0, 0xfe, 0xc7, 0xc3, 0xc3, 0xc7, 0xfe},
00435                 {0x00, 0x00, 0x7e, 0xe7, 0x03, 0x03, 0x07, 0x7e, 0xe0, 0xc0, 0xc0, 0xe7, 0x7e},
00436                 {0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xff},
00437                 {0x00, 0x00, 0x7e, 0xe7, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3},
00438                 {0x00, 0x00, 0x18, 0x3c, 0x3c, 0x66, 0x66, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3},
00439                 {0x00, 0x00, 0xc3, 0xe7, 0xff, 0xff, 0xdb, 0xdb, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3},
00440                 {0x00, 0x00, 0xc3, 0x66, 0x66, 0x3c, 0x3c, 0x18, 0x3c, 0x3c, 0x66, 0x66, 0xc3},
00441                 {0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x3c, 0x66, 0x66, 0xc3},
00442                 {0x00, 0x00, 0xff, 0xc0, 0xc0, 0x60, 0x30, 0x7e, 0x0c, 0x06, 0x03, 0x03, 0xff},
00443                 {0x00, 0x00, 0x3c, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x3c},
00444                 {0x00, 0x03, 0x03, 0x06, 0x06, 0x0c, 0x0c, 0x18, 0x18, 0x30, 0x30, 0x60, 0x60},
00445                 {0x00, 0x00, 0x3c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x3c},
00446                 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc3, 0x66, 0x3c, 0x18},
00447                 {0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
00448                 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x38, 0x30, 0x70},
00449                 {0x00, 0x00, 0x7f, 0xc3, 0xc3, 0x7f, 0x03, 0xc3, 0x7e, 0x00, 0x00, 0x00, 0x00},
00450                 {0x00, 0x00, 0xfe, 0xc3, 0xc3, 0xc3, 0xc3, 0xfe, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0},
00451                 {0x00, 0x00, 0x7e, 0xc3, 0xc0, 0xc0, 0xc0, 0xc3, 0x7e, 0x00, 0x00, 0x00, 0x00},
00452                 {0x00, 0x00, 0x7f, 0xc3, 0xc3, 0xc3, 0xc3, 0x7f, 0x03, 0x03, 0x03, 0x03, 0x03},
00453                 {0x00, 0x00, 0x7f, 0xc0, 0xc0, 0xfe, 0xc3, 0xc3, 0x7e, 0x00, 0x00, 0x00, 0x00},
00454                 {0x00, 0x00, 0x30, 0x30, 0x30, 0x30, 0x30, 0xfc, 0x30, 0x30, 0x30, 0x33, 0x1e},
00455                 {0x7e, 0xc3, 0x03, 0x03, 0x7f, 0xc3, 0xc3, 0xc3, 0x7e, 0x00, 0x00, 0x00, 0x00},
00456                 {0x00, 0x00, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xfe, 0xc0, 0xc0, 0xc0, 0xc0},
00457                 {0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x18, 0x00},
00458                 {0x38, 0x6c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x00, 0x00, 0x0c, 0x00},
00459                 {0x00, 0x00, 0xc6, 0xcc, 0xf8, 0xf0, 0xd8, 0xcc, 0xc6, 0xc0, 0xc0, 0xc0, 0xc0},
00460                 {0x00, 0x00, 0x7e, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x78},
00461                 {0x00, 0x00, 0xdb, 0xdb, 0xdb, 0xdb, 0xdb, 0xdb, 0xfe, 0x00, 0x00, 0x00, 0x00},
00462                 {0x00, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xfc, 0x00, 0x00, 0x00, 0x00},
00463                 {0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00},
00464                 {0xc0, 0xc0, 0xc0, 0xfe, 0xc3, 0xc3, 0xc3, 0xc3, 0xfe, 0x00, 0x00, 0x00, 0x00},
00465                 {0x03, 0x03, 0x03, 0x7f, 0xc3, 0xc3, 0xc3, 0xc3, 0x7f, 0x00, 0x00, 0x00, 0x00},
00466                 {0x00, 0x00, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xe0, 0xfe, 0x00, 0x00, 0x00, 0x00},
00467                 {0x00, 0x00, 0xfe, 0x03, 0x03, 0x7e, 0xc0, 0xc0, 0x7f, 0x00, 0x00, 0x00, 0x00},
00468                 {0x00, 0x00, 0x1c, 0x36, 0x30, 0x30, 0x30, 0x30, 0xfc, 0x30, 0x30, 0x30, 0x00},
00469                 {0x00, 0x00, 0x7e, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00, 0x00},
00470                 {0x00, 0x00, 0x18, 0x3c, 0x3c, 0x66, 0x66, 0xc3, 0xc3, 0x00, 0x00, 0x00, 0x00},
00471                 {0x00, 0x00, 0xc3, 0xe7, 0xff, 0xdb, 0xc3, 0xc3, 0xc3, 0x00, 0x00, 0x00, 0x00},
00472                 {0x00, 0x00, 0xc3, 0x66, 0x3c, 0x18, 0x3c, 0x66, 0xc3, 0x00, 0x00, 0x00, 0x00},
00473                 {0xc0, 0x60, 0x60, 0x30, 0x18, 0x3c, 0x66, 0x66, 0xc3, 0x00, 0x00, 0x00, 0x00},
00474                 {0x00, 0x00, 0xff, 0x60, 0x30, 0x18, 0x0c, 0x06, 0xff, 0x00, 0x00, 0x00, 0x00},
00475                 {0x00, 0x00, 0x0f, 0x18, 0x18, 0x18, 0x38, 0xf0, 0x38, 0x18, 0x18, 0x18, 0x0f},
00476                 {0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18},
00477                 {0x00, 0x00, 0xf0, 0x18, 0x18, 0x18, 0x1c, 0x0f, 0x1c, 0x18, 0x18, 0x18, 0xf0},
00478                 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x8f, 0xf1, 0x60, 0x00, 0x00, 0x00} 
00479         };
00480 
00481 
00482         int i;
00483         glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );                        // bit alignment
00484         gFontOffset = glGenLists( 128 );                                        // 128 display lists
00485         for( i = 32; i < 126; i++ )
00486         {
00487                 glNewList( i + gFontOffset, GL_COMPILE );               // make list
00488                         glBitmap( 8, 13, 0.0, 2.0, 10.0, 0.0, &rasterfont[i-32][0] );   // add each letter to the Dlist
00489                 glEndList();
00490         }
00491 
00492 
00493 }
00494 
00495 /******************************************************************************
00496 
00497  Public Funks
00498 
00499 ******************************************************************************/
00500 
00501 
00502 
00503 void glScreen2D( const int width, const int height, const int mode )
00504 {
00505         glScreen2DEx( width, height, mode, 0, 0 );
00506 }
00507 
00508 
00509 // GLFW_WINDOW or GLFW_FULLSCREEN
00510 void glScreen2DEx( const int width, const int height, const int mode, 
00511                                    const int depthbits, const int stencilbits )
00512 {
00513 
00514     glfwInit();
00515 
00516     if( !glfwOpenWindow( width, height,
00517                                                  0,                             // Red
00518                                                  0,                             // green
00519                                                  0,                             // Blue 
00520                                                  0,                             // Alpha
00521                                                  depthbits,                             // Depth
00522                                                  stencilbits,                           // Stencil
00523                                                  mode ) )
00524     {
00525         glfwTerminate();
00526     }
00527 
00528     glfwSetWindowTitle( "Easy GL2D" );
00529 
00530 
00531     double FOVy;
00532     double aspect;
00533     double znear;
00534     double zfar;
00535 
00536     // using screen info w and h as params
00537     glViewport( 0, 0, width, height );
00538 
00539     // Set current Mode to projection(ie: 3d)
00540     glMatrixMode( GL_PROJECTION );
00541 
00542     // Load identity matrix to projection matrix
00543     glLoadIdentity();
00544 
00545     // Set gluPerspective params
00546     FOVy = 90 / 2.0f;                                     //45 deg fovy
00547     aspect = width / (float)height;
00548     znear = 1;                                       //Near clip
00549     zfar = 500;                                      //far clip
00550 
00551     // use glu Perspective to set our 3d frustum dimension up
00552     gluPerspective( FOVy, aspect, znear, zfar );
00553 
00554     // Modelview mode
00555     // ie. Matrix that does things to anything we draw
00556     // as in lines, points, tris, etc.
00557     glMatrixMode( GL_MODELVIEW );
00558 
00559     // load identity(clean) matrix to modelview
00560     glLoadIdentity();
00561 
00562     glShadeModel( GL_SMOOTH );                 //'set shading to smooth(try GL_FLAT)
00563     glClearColor( 0.0, 0.0, 0.0, 1.0 );        //'set Clear color to BLACK
00564     glClearDepth( 1.0 );                       //'Set Depth buffer to 1(z-Buffer)
00565     glDisable( GL_DEPTH_TEST );                //'Disable Depth Testing so that our z-buffer works
00566 
00567     //'compare each incoming pixel z value with the z value present in the depth buffer
00568     //'LEQUAL means than pixel is drawn if the incoming z value is less than
00569     //'or equal to the stored z value
00570     glDepthFunc( GL_LEQUAL );
00571 
00572     //'have one or more material parameters track the current color
00573     //'Material is your 3d model
00574     glEnable( GL_COLOR_MATERIAL );
00575 
00576 
00577     //Enable Texturing
00578     glEnable( GL_TEXTURE_2D );
00579 
00580 
00581     //'Tell openGL that we want the best possible perspective transform
00582     glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );
00583 
00584     //'Disable Backface culling
00585     glDisable ( GL_CULL_FACE );
00586 
00587     glPolygonMode( GL_FRONT, GL_FILL );
00588 
00589     //'' enable blending for transparency
00590     glEnable( GL_BLEND );
00591     glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
00592 
00593     glDisable( GL_DEPTH_TEST );
00594 
00595     glEnable( GL_ALPHA_TEST );
00596     glAlphaFunc( GL_GREATER, 0 );
00597 
00598 
00599     glDisable( GL_STENCIL_TEST );
00600     glDisable( GL_TEXTURE_1D );
00601     glDisable( GL_LIGHTING );
00602     glDisable( GL_LOGIC_OP );
00603     glDisable( GL_DITHER );
00604     glDisable( GL_FOG );
00605 
00606     glHint( GL_POINT_SMOOTH_HINT, GL_NICEST );
00607     glHint( GL_LINE_SMOOTH_HINT , GL_NICEST );
00608 
00609     glPointSize( 1.0 );
00610     glLineWidth( 1.0 );
00611 
00612         FontInit();
00613 
00614 }
00615 
00616 
00617 /******************************************************************************
00618 
00619 
00620 ******************************************************************************/
00621 void glClose()
00622 {
00623         glDeleteTextures ( 1, &gGlowTexture );
00624 }
00625 
00626 /******************************************************************************
00627 
00628 
00629 ******************************************************************************/
00630 
00631 void glBlendMode( const GL2D_BLEND_MODE mode )
00632 {
00633     switch ( mode )
00634     {
00635         case GL2D_TRANS:
00636                         glDisable( GL_BLEND );
00637                         glEnable( GL_ALPHA_TEST );
00638                         break;
00639                 case GL2D_SOLID:
00640                         glDisable( GL_BLEND );
00641                         glDisable( GL_ALPHA_TEST );
00642                         break;
00643                 case GL2D_BLENDED:
00644                         glEnable( GL_BLEND );
00645                         glEnable( GL_ALPHA_TEST );
00646                         glBlendFunc( GL_SRC_ALPHA, GL_ONE );
00647                         break;
00648                 case GL2D_GLOW:
00649                         glEnable( GL_BLEND );
00650                         glEnable( GL_ALPHA_TEST );
00651                         glBlendFunc( GL_ONE, GL_ONE );
00652                         break;
00653         case GL2D_ALPHA:
00654                         glEnable( GL_BLEND );
00655                         glEnable( GL_ALPHA_TEST );
00656                         glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
00657                         break;
00658                 case GL2D_BLACK:
00659                         glEnable( GL_BLEND );
00660                         glEnable( GL_ALPHA_TEST );
00661                         glBlendFunc( GL_ZERO,GL_ONE_MINUS_SRC_ALPHA );
00662                         break;
00663                 default:
00664                         glDisable( GL_BLEND );
00665                         glEnable( GL_ALPHA_TEST );
00666         }
00667 
00668 }
00669 
00670 
00671 /******************************************************************************
00672 
00673 
00674 ******************************************************************************/
00675 
00676 void glClearScreen()
00677 {
00678 
00679     glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
00680     glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
00681 
00682 }
00683 
00684 
00685 /******************************************************************************
00686 
00687 
00688 ******************************************************************************/
00689 
00690 void glLineGlow( const int x1, const int y1,
00691                  const int x2, const int y2,
00692                  const int width, const GLuint color )
00693 {
00694 
00695         GLuint textureID;
00696 
00697         textureID = GetGlowImage();
00698 
00699     glColor4ubv ( (GLubyte*)(&color) ) ;
00700 
00701         // Only change active texture when there is a need
00702         // Speeds up the rendering by batching textures
00703 
00704     if ( textureID != gCurrentTexture )
00705     {
00706         glBindTexture( GL_TEXTURE_2D, textureID );
00707         gCurrentTexture = textureID;
00708     }
00709 
00710 
00711         float nx,ny;
00712         nx = -( y2-y1 );
00713         ny =  ( x2-x1 );
00714 
00715         float leng;
00716     leng = sqrt( nx * nx + ny * ny );
00717     nx = nx / leng;
00718     ny = ny / leng;
00719 
00720         nx *= width / 2.0;
00721         ny *= width / 2.0;
00722 
00723         float lx1, ly1, lx2, ly2, lx3, ly3, lx4, ly4;
00724 
00725         lx1 = x2 + nx;
00726     ly1 = y2 + ny;
00727     lx2 = x2 - nx;
00728     ly2 = y2 - ny;
00729     lx3 = x1 - nx;
00730     ly3 = y1 - ny;
00731     lx4 = x1 + nx;
00732     ly4 = y1 + ny;
00733 
00734         // MAIN
00735         glBegin( GL_QUADS );
00736                 glTexCoord2f( 0.5, 0.0 ); glVertex3f( lx1, ly1, 0.0 );
00737                 glTexCoord2f( 0.5, 1.0 ); glVertex3f( lx2, ly2, 0.0 );
00738                 glTexCoord2f( 0.5, 1.0 ); glVertex3f( lx3, ly3, 0.0 );
00739                 glTexCoord2f( 0.5, 0.0 ); glVertex3f( lx4, ly4, 0.0 );
00740         glEnd();
00741 
00742         //RIGHT
00743         float lx5, ly5, lx6, ly6, vx, vy;
00744         vx = ( x2-x1 );
00745         vy = ( y2-y1 );
00746         leng = sqrt( vx * vx + vy * vy );
00747         vx = vx / leng;
00748         vy = vy / leng;
00749         vx *= width / 2.0;
00750         vy *= width / 2.0;
00751 
00752         lx5 = lx1 + vx;
00753         ly5 = ly1 + vy;
00754         lx6 = lx2 + vx;
00755         ly6 = ly2 + vy;
00756 
00757         glBegin( GL_QUADS );
00758                 glTexCoord2f( 0.5, 0.0 ); glVertex3f( lx1, ly1,0.0 );
00759                 glTexCoord2f( 1.0, 0.0 ); glVertex3f( lx5, ly5,0.0 );
00760                 glTexCoord2f( 1.0, 1.0 ); glVertex3f( lx6, ly6,0.0 );
00761                 glTexCoord2f( 0.5, 1.0 ); glVertex3f( lx2, ly2,0.0 );
00762         glEnd();
00763 
00764         // LEFT
00765         lx5 = lx4 - vx;
00766         ly5 = ly4 - vy;
00767         lx6 = lx3 - vx;
00768         ly6 = ly3 - vy;
00769 
00770         glBegin( GL_QUADS );
00771                 glTexCoord2f( 0.5, 0.0 ); glVertex3f( lx4, ly4, 0.0 );
00772                 glTexCoord2f( 0.5, 1.0 ); glVertex3f( lx3, ly3 ,0.0 );
00773                 glTexCoord2f( 1.0, 1.0 ); glVertex3f( lx6, ly6, 0.0 );
00774                 glTexCoord2f( 1.0, 0.0 ); glVertex3f( lx5, ly5, 0.0 );
00775         glEnd();
00776 
00777         glColor4ub( 255, 255, 255, 255 );
00778 
00779 }
00780 
00781 
00782 /******************************************************************************
00783 
00784 
00785 ******************************************************************************/
00786 void glPutPixel( int x, int y, const GLuint color )
00787 {
00788     glDisable( GL_TEXTURE_2D );
00789     glColor4ubv ( (GLubyte*)(&color)) ;
00790 
00791     glBegin( GL_POINTS );
00792                 glVertex2i( x, y );
00793         glEnd();
00794 
00795     glEnable( GL_TEXTURE_2D );
00796 
00797     glColor4ub( 255, 255, 255, 255 );
00798 
00799 }
00800 
00801 /******************************************************************************
00802 
00803 
00804 ******************************************************************************/
00805 void glLine( int x1, int y1, int x2, int y2, const GLuint color )
00806 {
00807     glDisable( GL_TEXTURE_2D );
00808     glColor4ubv ( (GLubyte*)(&color)) ;
00809 
00810     glBegin( GL_LINES );
00811                 glVertex2i( x1, y1 );
00812                 glVertex2i( x2, y2 );
00813         glEnd();
00814 
00815     glEnable( GL_TEXTURE_2D );
00816 
00817     glColor4ub( 255, 255, 255, 255 );
00818 
00819 }
00820 
00821 /******************************************************************************
00822 
00823 
00824 ******************************************************************************/
00825 void glLineGradient( int x1, int y1, int x2, int y2,
00826                      const GLuint color1, const GLuint color2 )
00827 {
00828     glDisable( GL_TEXTURE_2D );
00829 
00830     glBegin( GL_LINES );
00831                 glColor4ubv( (GLubyte*)(&color1) ); glVertex2i( x1, y1 );
00832                 glColor4ubv( (GLubyte*)(&color2) ); glVertex2i( x2, y2 );
00833         glEnd();
00834 
00835     glEnable( GL_TEXTURE_2D );
00836 
00837     glColor4ub( 255, 255, 255, 255 );
00838 
00839 }
00840 
00841 /******************************************************************************
00842 
00843 
00844 ******************************************************************************/
00845 void glBox( int x1, int y1, int x2, int y2, const GLuint color )
00846 {
00847     glDisable( GL_TEXTURE_2D );
00848     glColor4ubv ( (GLubyte*)(&color)) ;
00849 
00850     glBegin( GL_LINE_STRIP );
00851                 glVertex2i( x1, y1 );
00852                 glVertex2i( x2, y1 );
00853                 glVertex2i( x2, y2 );
00854                 glVertex2i( x1, y2 );
00855                 glVertex2i( x1, y1 );
00856         glEnd();
00857 
00858     glEnable( GL_TEXTURE_2D );
00859 
00860     glColor4ub( 255, 255, 255, 255 );
00861 
00862 }
00863 
00864 /******************************************************************************
00865 
00866 
00867 ******************************************************************************/
00868 
00869 void glBoxFilled( int x1, int y1, int x2, int y2, const GLuint color )
00870 {
00871     glDisable( GL_TEXTURE_2D );
00872     glColor4ubv ( (GLubyte*)(&color)) ;
00873 
00874     x2++;
00875     y2++;
00876 
00877     glBegin( GL_QUADS );
00878 
00879         glVertex2i      ( x1,y1 );
00880         glVertex2i      ( x1,y2 );
00881         glVertex2i      ( x2,y2 );
00882         glVertex2i      ( x2,y1 );
00883 
00884     glEnd();
00885 
00886     glEnable( GL_TEXTURE_2D );
00887 
00888     glColor4ub( 255, 255, 255, 255 );
00889 
00890 }
00891 
00892 
00893 /******************************************************************************
00894 
00895 
00896 ******************************************************************************/
00897 
00898 void glBoxFilledGradient( int x1, int y1, int x2, int y2,
00899                           const GLuint color1, const GLuint color2,
00900                           const GLuint color3, const GLuint color4 )
00901 {
00902     glDisable( GL_TEXTURE_2D );
00903 
00904     x2++;
00905     y2++;
00906 
00907     glBegin( GL_QUADS );
00908 
00909         glColor4ubv( (GLubyte*)(&color1) ); glVertex2i( x1,y1 );
00910         glColor4ubv( (GLubyte*)(&color2) ); glVertex2i( x1,y2 );
00911         glColor4ubv( (GLubyte*)(&color3) ); glVertex2i( x2,y2 );
00912         glColor4ubv( (GLubyte*)(&color4) ); glVertex2i( x2,y1 );
00913 
00914     glEnd();
00915 
00916     glEnable( GL_TEXTURE_2D );
00917 
00918     glColor4ub( 255, 255, 255, 255 );
00919 
00920 }
00921 
00922 
00923 /******************************************************************************
00924 
00925 
00926 ******************************************************************************/
00927 void glTriangle( int x1, int y1, int x2, int y2, int x3, int y3, const GLuint color )
00928 {
00929     glDisable( GL_TEXTURE_2D );
00930     glColor4ubv ( (GLubyte*)(&color)) ;
00931 
00932     glBegin( GL_LINE_STRIP );
00933                 glVertex2i( x1, y1 );
00934                 glVertex2i( x2, y2 );
00935                 glVertex2i( x3, y3 );
00936                 glVertex2i( x1, y1 );
00937         glEnd();
00938 
00939     glEnable( GL_TEXTURE_2D );
00940 
00941     glColor4ub( 255, 255, 255, 255 );
00942 
00943 }
00944 
00945 /******************************************************************************
00946 
00947 
00948 ******************************************************************************/
00949 void glTriangleFilled( int x1, int y1, int x2, int y2, int x3, int y3, const GLuint color )
00950 {
00951     glDisable( GL_TEXTURE_2D );
00952     glColor4ubv ( (GLubyte*)(&color)) ;
00953 
00954     glBegin( GL_TRIANGLES );
00955                 glVertex2i( x1, y1 );
00956                 glVertex2i( x2, y2 );
00957                 glVertex2i( x3, y3 );
00958         glEnd();
00959 
00960     glEnable( GL_TEXTURE_2D );
00961 
00962     glColor4ub( 255, 255, 255, 255 );
00963 
00964 }
00965 
00966 
00967 /******************************************************************************
00968 
00969 
00970 ******************************************************************************/
00971 void glTriangleFilledGradient( int x1, int y1, int x2, int y2, int x3, int y3,
00972                                const GLuint color1, const GLuint color2, const GLuint color3 )
00973 {
00974     glDisable( GL_TEXTURE_2D );
00975 
00976     glBegin( GL_TRIANGLES );
00977                 glColor4ubv( (GLubyte*)(&color1) ); glVertex2i( x1, y1 );
00978                 glColor4ubv( (GLubyte*)(&color2) ); glVertex2i( x2, y2 );
00979                 glColor4ubv( (GLubyte*)(&color3) ); glVertex2i( x3, y3 );
00980         glEnd();
00981 
00982     glEnable( GL_TEXTURE_2D );
00983 
00984     glColor4ub( 255, 255, 255, 255 );
00985 
00986 }
00987 
00988 /******************************************************************************
00989 
00990     Contributed by Michael "h4tt3n" Nissen(I added a filled version ;*))
00991     syntax: ellipse(center x, center y, semimajor axis, semiminor axis, angle in degrees, color)
00992 
00993 ******************************************************************************/
00994 void glEllipse( int x, int y, int a, int b, int degrees, const GLuint color )
00995 {
00996 
00997         // these constants decide the quality of the ellipse
00998         const float  pi = M_PI;
00999         const float  twopi  = 2 * pi;   //        two pi (radians in a circle)
01000         const int face_length  = 8;     //        approx. face length in pixels
01001         const int max_faces = 256;      //        maximum number of faces in ellipse
01002         const int min_faces = 16;       //        minimum number of faces in ellipse
01003 
01004         // approx. ellipse circumference (hudson's method)
01005         float h = ( a-b*a-b ) / (float)( a+b*a+b );
01006         float circumference = 0.25 * pi * (a+b) * (3* (1+h*0.25)+1 / (float)(1-h*0.25));
01007 
01008         // number of faces in ellipse
01009         int num_faces = circumference/face_length;
01010 
01011         // clamp number of faces
01012         if( num_faces > max_faces ) num_faces = max_faces;
01013         if( num_faces < min_faces ) num_faces = min_faces;
01014 
01015         // keep number of faces divisible by 4
01016         num_faces -= (num_faces & 3);
01017 
01018         // precalc cosine theta
01019         float angle = degrees * M_PI /180.0;
01020         float s   = sin(twopi/(float)num_faces);
01021         float c   = cos(twopi/(float)num_faces);
01022         float xx  = 1;
01023         float yy  = 0;
01024         float xt  = 0;
01025         float ax  = cos(angle);
01026         float ay  = sin(angle);
01027 
01028 
01029         // draw ellipse
01030         glDisable( GL_TEXTURE_2D );
01031         glColor4ubv( (GLubyte*)(&color) );
01032 
01033     int i;
01034         glBegin( GL_LINE_LOOP );
01035 
01036                 for( i = 0; i < num_faces; i++ )
01037                 {
01038                     xt = xx;
01039                         xx = c * xx - s * yy;
01040                         yy = s * xt + c * yy;
01041                         glVertex2f( x+a*xx*ax-b*yy*ay, y+a*xx*ay+b*yy*ax );
01042                 }
01043 
01044                 glVertex2f( x+a*ax, y+a*ay );
01045 
01046         glEnd();
01047 
01048         glEnable( GL_TEXTURE_2D );
01049 
01050         glColor4ub( 255, 255, 255,255 );
01051 
01052 }
01053 
01054 /******************************************************************************
01055 
01056     Contributed by Michael "h4tt3n" Nissen(I added a filled version ;*))
01057     syntax: ellipse(center x, center y, semimajor axis, semiminor axis, angle in degrees, color)
01058 
01059 ******************************************************************************/
01060 void glEllipseFilled( int x, int y, int a, int b, int degrees, const GLuint color )
01061 {
01062 
01063         // these constants decide the quality of the ellipse
01064         const float  pi = M_PI;
01065         const float  twopi  = 2 * pi;   //        two pi (radians in a circle)
01066         const int face_length  = 8;     //        approx. face length in pixels
01067         const int max_faces = 256;      //        maximum number of faces in ellipse
01068         const int min_faces = 16;       //        minimum number of faces in ellipse
01069 
01070         // approx. ellipse circumference (hudson's method)
01071         float h = ( a-b*a-b ) / (float)( a+b*a+b );
01072         float circumference = 0.25 * pi * (a+b) * (3* (1+h*0.25)+1 / (float)(1-h*0.25));
01073 
01074         // number of faces in ellipse
01075         int num_faces = circumference/face_length;
01076 
01077         // clamp number of faces
01078         if( num_faces > max_faces ) num_faces = max_faces;
01079         if( num_faces < min_faces ) num_faces = min_faces;
01080 
01081         // keep number of faces divisible by 4
01082         num_faces -= (num_faces & 3);
01083 
01084         // precalc cosine theta
01085         float angle = degrees * M_PI /180.0;
01086         float s   = sin(twopi/(float)num_faces);
01087         float c   = cos(twopi/(float)num_faces);
01088         float xx  = 1;
01089         float yy  = 0;
01090         float xt  = 0;
01091         float ax  = cos(angle);
01092         float ay  = sin(angle);
01093 
01094 
01095         // draw ellipse
01096         glDisable( GL_TEXTURE_2D );
01097         glColor4ubv( (GLubyte*)(&color) );
01098 
01099     int i;
01100         glBegin( GL_TRIANGLE_FAN );
01101 
01102                 for( i = 0; i < num_faces; i++ )
01103                 {
01104                     xt = xx;
01105                         xx = c * xx - s * yy;
01106                         yy = s * xt + c * yy;
01107                         glVertex2f( x+a*xx*ax-b*yy*ay, y+a*xx*ay+b*yy*ax );
01108                 }
01109 
01110                 glVertex2f( x+a*ax, y+a*ay );
01111 
01112         glEnd();
01113 
01114         glEnable( GL_TEXTURE_2D );
01115 
01116         glColor4ub( 255, 255, 255,255 );
01117 
01118 }
01119 
01120 /******************************************************************************
01121 
01122     Draws a sprite
01123         Parameters:
01124        x                -> x position of the sprite
01125            y            -> y position of the sprite
01126            flipmode -> mode for flipping (see GL_FLIP_MODE enum)
01127            *spr         -> pointer to a glImage
01128 
01129 ******************************************************************************/
01130 void glSprite( const int x, const int y, const int flipmode, const glImage *spr )
01131 {
01132     int x1 = x;
01133     int y1 = y;
01134     int x2 = x + spr->width;
01135     int y2 = y + spr->height;
01136 
01137     float u1 = ( flipmode & GL2D_FLIP_H ) ? spr->u_off + spr->u_width  : spr->u_off;
01138     float u2 = ( flipmode & GL2D_FLIP_H ) ? spr->u_off                         : spr->u_off + spr->u_width;
01139     float v1 = ( flipmode & GL2D_FLIP_V ) ? spr->v_off + spr->v_height : spr->v_off;
01140     float v2 = ( flipmode & GL2D_FLIP_V ) ? spr->v_off                         : spr->v_off + spr->v_height;
01141 
01142 
01143     if ( spr->textureID != gCurrentTexture )
01144     {
01145         glBindTexture( GL_TEXTURE_2D, spr->textureID );
01146         gCurrentTexture = spr->textureID;
01147     }
01148 
01149     glBegin( GL_QUADS );
01150 
01151         glTexCoord2f( u1, v1 ); glVertex2i( x1, y1 );
01152         glTexCoord2f( u1, v2 ); glVertex2i( x1, y2 );
01153         glTexCoord2f( u2, v2 ); glVertex2i( x2, y2 );
01154         glTexCoord2f( u2, v1 ); glVertex2i( x2, y1 );
01155 
01156     glEnd();
01157 
01158 
01159 }
01160 
01161 /******************************************************************************
01162 
01163     Draws a scaled sprite
01164         Parameters:
01165        x                -> x position of the sprite
01166            y            -> y position of the sprite
01167            scale    -> float value to scale the sprite (1.0 for no scaling)
01168            flipmode -> mode for flipping (see GL_FLIP_MODE enum)
01169            *spr         -> pointer to a glImage
01170 
01171 ******************************************************************************/
01172 void glSpriteScale( const int x, const int y, const float scale, const int flipmode, const glImage *spr )
01173 {
01174     int x1 = 0;
01175     int y1 = 0;
01176     int x2 = spr->width;
01177     int y2 = spr->height;
01178 
01179     float u1 = ( flipmode & GL2D_FLIP_H ) ? spr->u_off + spr->u_width  : spr->u_off;
01180     float u2 = ( flipmode & GL2D_FLIP_H ) ? spr->u_off                         : spr->u_off + spr->u_width;
01181     float v1 = ( flipmode & GL2D_FLIP_V ) ? spr->v_off + spr->v_height : spr->v_off;
01182     float v2 = ( flipmode & GL2D_FLIP_V ) ? spr->v_off                         : spr->v_off + spr->v_height;
01183 
01184 
01185     if ( spr->textureID != gCurrentTexture )
01186     {
01187         glBindTexture( GL_TEXTURE_2D, spr->textureID );
01188         gCurrentTexture = spr->textureID;
01189     }
01190 
01191     glPushMatrix();
01192 
01193     glTranslatef( x, y, 0.0 );
01194     glScalef( scale, scale, 1.0 );
01195 
01196     glBegin( GL_QUADS );
01197 
01198         glTexCoord2f( u1, v1 ); glVertex2i( x1, y1 );
01199         glTexCoord2f( u1, v2 ); glVertex2i( x1, y2 );
01200         glTexCoord2f( u2, v2 ); glVertex2i( x2, y2 );
01201         glTexCoord2f( u2, v1 ); glVertex2i( x2, y1 );
01202 
01203     glEnd();
01204 
01205     glPopMatrix();
01206 
01207 }
01208 
01209 
01210 /******************************************************************************
01211 
01212     Draws a scaled sprite
01213         Parameters:
01214        x                -> x position of the sprite
01215            y            -> y position of the sprite
01216            scale    -> float value to scale the sprite (1.0 for no scaling)
01217            flipmode -> mode for flipping (see GL_FLIP_MODE enum)
01218            *spr         -> pointer to a glImage
01219 
01220 ******************************************************************************/
01221 void glSpriteScaleXY( const int x, const int y, const float scaleX, const float scaleY, const int flipmode, const glImage *spr )
01222 {
01223     int x1 = 0;
01224     int y1 = 0;
01225     int x2 = spr->width;
01226     int y2 = spr->height;
01227 
01228     float u1 = ( flipmode & GL2D_FLIP_H ) ? spr->u_off + spr->u_width  : spr->u_off;
01229     float u2 = ( flipmode & GL2D_FLIP_H ) ? spr->u_off                         : spr->u_off + spr->u_width;
01230     float v1 = ( flipmode & GL2D_FLIP_V ) ? spr->v_off + spr->v_height : spr->v_off;
01231     float v2 = ( flipmode & GL2D_FLIP_V ) ? spr->v_off                         : spr->v_off + spr->v_height;
01232 
01233 
01234     if ( spr->textureID != gCurrentTexture )
01235     {
01236         glBindTexture( GL_TEXTURE_2D, spr->textureID );
01237         gCurrentTexture = spr->textureID;
01238     }
01239 
01240     glPushMatrix();
01241 
01242     glTranslatef( x, y, 0.0 );
01243     glScalef( scaleX, scaleY, 1.0 );
01244 
01245     glBegin( GL_QUADS );
01246 
01247         glTexCoord2f( u1, v1 ); glVertex2i( x1, y1 );
01248         glTexCoord2f( u1, v2 ); glVertex2i( x1, y2 );
01249         glTexCoord2f( u2, v2 ); glVertex2i( x2, y2 );
01250         glTexCoord2f( u2, v1 ); glVertex2i( x2, y1 );
01251 
01252     glEnd();
01253 
01254     glPopMatrix();
01255 
01256 }
01257 
01258 /******************************************************************************
01259 
01260     Draws a center rotated sprite
01261         Parameters:
01262        x                -> x position of the sprite center
01263            y            -> y position of the sprite center
01264            angle    -> is the angle to rotated (in degrees)
01265            flipmode -> mode for flipping (see GL_FLIP_MODE enum)
01266            *spr         -> pointer to a glImage
01267 
01268 ******************************************************************************/
01269 void glSpriteRotate( const int x, const int y, const int angle, const int flipmode, const glImage *spr )
01270 {
01271 
01272     int s_half_x = spr->width/2;
01273     int s_half_y = spr->height/2;
01274 
01275     int x1 =  -s_half_x;
01276     int y1 =  -s_half_y;
01277 
01278     int x2 =  s_half_x;
01279     int y2 =  s_half_y;
01280 
01281 
01282     float u1 = ( flipmode & GL2D_FLIP_H ) ? spr->u_off + spr->u_width  : spr->u_off;
01283     float u2 = ( flipmode & GL2D_FLIP_H ) ? spr->u_off                         : spr->u_off + spr->u_width;
01284     float v1 = ( flipmode & GL2D_FLIP_V ) ? spr->v_off + spr->v_height : spr->v_off;
01285     float v2 = ( flipmode & GL2D_FLIP_V ) ? spr->v_off                         : spr->v_off + spr->v_height;
01286 
01287 
01288     if ( spr->textureID != gCurrentTexture )
01289     {
01290         glBindTexture( GL_TEXTURE_2D, spr->textureID );
01291         gCurrentTexture = spr->textureID;
01292     }
01293 
01294     glPushMatrix();
01295 
01296     glTranslatef( x, y, 0.0 );
01297     glRotatef( angle, 0.0, 0.0, 1.0 );
01298 
01299 
01300     glBegin( GL_QUADS );
01301 
01302         glTexCoord2f( u1, v1 ); glVertex2i( x1, y1 );
01303         glTexCoord2f( u1, v2 ); glVertex2i( x1, y2 );
01304         glTexCoord2f( u2, v2 ); glVertex2i( x2, y2 );
01305         glTexCoord2f( u2, v1 ); glVertex2i( x2, y1 );
01306 
01307     glEnd();
01308 
01309     glPopMatrix();
01310 
01311 
01312 }
01313 
01314 
01315 
01316 /******************************************************************************
01317 
01318     Draws a center rotated and scaled sprite
01319         Parameters:
01320        x                -> x position of the sprite center
01321            y            -> y position of the sprite center
01322            angle    -> is the angle to rotated (-32768 to 32767)
01323            scale    -> is a 20.12 FP scale value (you can use floattof32(1.45) to scale
01324                        and GCC would optimize it to a constant)
01325            flipmode -> mode for flipping (see GL_FLIP_MODE enum)
01326            *spr         -> pointer to a glImage
01327 
01328 ******************************************************************************/
01329 void glSpriteRotateScale( const int x, const int y, const int angle, const float scale, const int flipmode, const glImage *spr )
01330 {
01331 
01332     int s_half_x = spr->width / 2;
01333     int s_half_y = spr->height / 2;
01334 
01335     int x1 =  -s_half_x;
01336     int y1 =  -s_half_y;
01337 
01338     int x2 =  s_half_x;
01339     int y2 =  s_half_y;
01340 
01341 
01342     float u1 = ( flipmode & GL2D_FLIP_H ) ? spr->u_off + spr->u_width  : spr->u_off;
01343     float u2 = ( flipmode & GL2D_FLIP_H ) ? spr->u_off                         : spr->u_off + spr->u_width;
01344     float v1 = ( flipmode & GL2D_FLIP_V ) ? spr->v_off + spr->v_height : spr->v_off;
01345     float v2 = ( flipmode & GL2D_FLIP_V ) ? spr->v_off                         : spr->v_off + spr->v_height;
01346 
01347 
01348     if ( spr->textureID != gCurrentTexture )
01349     {
01350         glBindTexture( GL_TEXTURE_2D, spr->textureID );
01351         gCurrentTexture = spr->textureID;
01352     }
01353 
01354     glPushMatrix();
01355 
01356     glTranslatef( x, y, 0.0 );
01357     glScalef( scale, scale, 1.0 );
01358     glRotatef(angle, 0.0, 0.0, 1.0);
01359 
01360     glBegin( GL_QUADS );
01361 
01362         glTexCoord2f( u1, v1 ); glVertex2i( x1, y1 );
01363         glTexCoord2f( u1, v2 ); glVertex2i( x1, y2 );
01364         glTexCoord2f( u2, v2 ); glVertex2i( x2, y2 );
01365         glTexCoord2f( u2, v1 ); glVertex2i( x2, y1 );
01366 
01367     glEnd();
01368 
01369     glPopMatrix();
01370 
01371 
01372 }
01373 
01374 /******************************************************************************
01375 
01376     Draws a center rotated and scaled sprite
01377         Parameters:
01378        x                -> x position of the sprite center
01379            y            -> y position of the sprite center
01380            angle    -> is the angle to rotated (-32768 to 32767)
01381            scale    -> is a 20.12 FP scale value (you can use floattof32(1.45) to scale
01382                        and GCC would optimize it to a constant)
01383            flipmode -> mode for flipping (see GL_FLIP_MODE enum)
01384            *spr         -> pointer to a glImage
01385 
01386 ******************************************************************************/
01387 void glSpriteRotateScaleXY( const int x, const int y, const int angle, const float scaleX, const float scaleY, const int flipmode, const glImage *spr )
01388 {
01389 
01390     int s_half_x = spr->width / 2;
01391     int s_half_y = spr->height / 2;
01392 
01393     int x1 =  -s_half_x;
01394     int y1 =  -s_half_y;
01395 
01396     int x2 =  s_half_x;
01397     int y2 =  s_half_y;
01398 
01399 
01400     float u1 = ( flipmode & GL2D_FLIP_H ) ? spr->u_off + spr->u_width  : spr->u_off;
01401     float u2 = ( flipmode & GL2D_FLIP_H ) ? spr->u_off                         : spr->u_off + spr->u_width;
01402     float v1 = ( flipmode & GL2D_FLIP_V ) ? spr->v_off + spr->v_height : spr->v_off;
01403     float v2 = ( flipmode & GL2D_FLIP_V ) ? spr->v_off                         : spr->v_off + spr->v_height;
01404 
01405 
01406     if ( spr->textureID != gCurrentTexture )
01407     {
01408         glBindTexture( GL_TEXTURE_2D, spr->textureID );
01409         gCurrentTexture = spr->textureID;
01410     }
01411 
01412     glPushMatrix();
01413 
01414     glTranslatef( x, y, 0.0 );
01415     glScalef( scaleX, scaleY, 1.0 );
01416     glRotatef(angle, 0.0, 0.0, 1.0);
01417 
01418     glBegin( GL_QUADS );
01419 
01420         glTexCoord2f( u1, v1 ); glVertex2i( x1, y1 );
01421         glTexCoord2f( u1, v2 ); glVertex2i( x1, y2 );
01422         glTexCoord2f( u2, v2 ); glVertex2i( x2, y2 );
01423         glTexCoord2f( u2, v1 ); glVertex2i( x2, y1 );
01424 
01425     glEnd();
01426 
01427     glPopMatrix();
01428 
01429 
01430 }
01431 
01432 /******************************************************************************
01433 
01434     Draws a sprite stretched on a quad
01435         Parameters:
01436                 x1                      -> x1 position of the sprite
01437                 y1                      -> y1 position of the sprite
01438                 x2                      -> x2 position of the sprite
01439                 y2                      -> y2 position of the sprite
01440                 x3                      -> x3 position of the sprite
01441                 y3                      -> y3 position of the sprite
01442                 x4                      -> x4 position of the sprite
01443                 y4                      -> y4 position of the sprite
01444                 flipmode        -> mode for flipping (see GL_FLIP_MODE enum)
01445                 *spr            -> pointer to a glImage
01446  
01447 ******************************************************************************/
01448 void glSpriteOnQuad( int x1, int y1,
01449                                          int x2, int y2,
01450                                          int x3, int y3,
01451                                          int x4, int y4,
01452                                          float uoff, float voff,
01453                                          int flipmode, const glImage *spr )
01454 {
01455         
01456         float u1 = ( flipmode & GL2D_FLIP_H ) ? spr->u_off + spr->u_width  : spr->u_off;
01457     float u2 = ( flipmode & GL2D_FLIP_H ) ? spr->u_off                         : spr->u_off + spr->u_width;
01458     float v1 = ( flipmode & GL2D_FLIP_V ) ? spr->v_off + spr->v_height : spr->v_off;
01459     float v2 = ( flipmode & GL2D_FLIP_V ) ? spr->v_off                         : spr->v_off + spr->v_height;
01460 
01461 
01462     if ( spr->textureID != gCurrentTexture )
01463     {
01464         glBindTexture( GL_TEXTURE_2D, spr->textureID );
01465         gCurrentTexture = spr->textureID;
01466     }
01467 
01468 
01469         glBegin( GL_QUADS );
01470                 
01471                 glTexCoord2f( u1+uoff, v1+voff ); glVertex2i( x1, y1 ); 
01472                 glTexCoord2f( u1+uoff, v2+voff ); glVertex2i( x2, y2 );
01473                 glTexCoord2f( u2+uoff, v2+voff ); glVertex2i( x3, y3 );
01474                 glTexCoord2f( u2+uoff, v1+voff ); glVertex2i( x4, y4 );
01475                 
01476         glEnd();
01477         
01478 }
01479 
01480 
01481 /******************************************************************************
01482 
01483     Draws a sprite stretched on a quad
01484         Parameters:
01485                 x1                      -> x1 position of the sprite
01486                 y1                      -> y1 position of the sprite
01487                 x2                      -> x2 position of the sprite
01488                 y2                      -> y2 position of the sprite
01489                 x3                      -> x3 position of the sprite
01490                 y3                      -> y3 position of the sprite
01491                 x4                      -> x4 position of the sprite
01492                 y4                      -> y4 position of the sprite
01493                 flipmode        -> mode for flipping (see GL_FLIP_MODE enum)
01494                 *spr            -> pointer to a glImage
01495  
01496 ******************************************************************************/
01497 void glSpriteOnQuadClipped( int x1, int y1,
01498                                                         int x2, int y2,
01499                                                         int x3, int y3,
01500                                                         int x4, int y4,
01501                                                         float luclip, float lvclip,
01502                                                         float ruclip, float rvclip,
01503                                                         int flipmode, const glImage *spr )
01504 {
01505         
01506         
01507         float u1 = spr->u_off + (( flipmode & GL2D_FLIP_H ) ? spr->u_width-(ruclip) : luclip);
01508         float u2 = spr->u_off + (( flipmode & GL2D_FLIP_H ) ? luclip                    : spr->u_width-(ruclip));
01509         float v1 = spr->v_off + (( flipmode & GL2D_FLIP_V ) ? spr->v_height-(rvclip): lvclip);
01510         float v2 = spr->v_off + (( flipmode & GL2D_FLIP_V ) ? lvclip                    : spr->v_height-(rvclip));
01511         
01512  
01513     if ( spr->textureID != gCurrentTexture )
01514     {
01515         glBindTexture( GL_TEXTURE_2D, spr->textureID );
01516         gCurrentTexture = spr->textureID;
01517     }
01518 
01519         glBegin( GL_QUADS );
01520                 
01521                 glTexCoord2f( u1, v1 ); glVertex2i( x1, y1 );   
01522                 glTexCoord2f( u1, v2 ); glVertex2i( x2, y2 );
01523                 glTexCoord2f( u2, v2 ); glVertex2i( x3, y3 );
01524                 glTexCoord2f( u2, v1 ); glVertex2i( x4, y4 );
01525                 
01526         glEnd();
01527         
01528         
01529 }
01530 
01531 
01532 
01533 /******************************************************************************
01534 
01535     Draws a sprite cleanly stretched horizontally
01536         Parameters:
01537                 x                       -> x1 position of the sprite
01538                 y                       -> y1 position of the sprite
01539                 flipmode        -> mode for flipping (see GL_FLIP_MODE enum)
01540                 *spr            -> pointer to a glImage
01541  
01542 ******************************************************************************/
01543 void glSpriteStretchHorizontal( int x, int y, int length, const glImage *spr )  
01544 {       
01545         int hw = (spr->width/2);
01546 
01547         int x1 = x;
01548         int y1 = y;
01549         int x2 = x + length;
01550         int y2 = y + spr->height;
01551         
01552         float u_off = spr->u_off;
01553         float v_off = spr->v_off;
01554         
01555         float u_width = spr->u_width;
01556         float v_height = spr->v_height;
01557 
01558         float su = u_width/2.0f;
01559                 
01560         if ( spr->textureID != gCurrentTexture )
01561     {
01562         glBindTexture( GL_TEXTURE_2D, spr->textureID );
01563         gCurrentTexture = spr->textureID;
01564     }
01565         
01566         // left
01567         int x2l = x1 + hw;
01568         
01569         glBegin( GL_QUADS );
01570         
01571                 glTexCoord2f( u_off, v_off );
01572                 glVertex2i( x1, y1 );
01573                 
01574                 glTexCoord2f( u_off, v_off + v_height );
01575                 glVertex2i( x1, y2 );
01576                 
01577                 glTexCoord2f( u_off + su, v_off + v_height );
01578                 glVertex2i( x2l, y2 );
01579                 
01580                 glTexCoord2f( u_off + su, v_off );
01581                 glVertex2i( x2l, y1 );
01582                 
01583         glEnd();
01584         
01585         // center
01586         int x1l = x + hw;
01587         x2l = x2 - hw - 1;
01588         
01589         glBegin( GL_QUADS );
01590         
01591                 glTexCoord2f( u_off + su, v_off );
01592                 glVertex2i( x1l,y1 );
01593                                 
01594                 glTexCoord2f( u_off + su, v_off + v_height );
01595                 glVertex2i( x1l,y2 );
01596                 
01597                 glTexCoord2f( u_off + su, v_off + v_height );
01598                 glVertex2i( x2l, y2 );
01599                 
01600                 glTexCoord2f( u_off + su, v_off );
01601                 glVertex2i( x2l, y1 );
01602                 
01603         glEnd();
01604         
01605         // right
01606         x1l = x2 - hw - 1;
01607         
01608         glBegin( GL_QUADS );
01609         
01610                 glTexCoord2f( u_off + su, v_off );
01611                 glVertex2i( x1l,y1 );
01612                 
01613                 glTexCoord2f( u_off + su, v_off + v_height );
01614                 glVertex2i( x1l, y2 );
01615                 
01616                 glTexCoord2f( u_off + u_width, v_off + v_height );
01617                 glVertex2i( x2, y2 );
01618                 
01619                 glTexCoord2f( u_off + u_width, v_off );
01620                 glVertex2i( x2, y1 );
01621                 
01622         glEnd();
01623         
01624 }
01625 
01626 /******************************************************************************
01627 
01628     Draws a sprite cleanly stretched vertically
01629         Parameters:
01630                 x                       -> x1 position of the sprite
01631                 y                       -> y1 position of the sprite
01632                 flipmode        -> mode for flipping (see GL_FLIP_MODE enum)
01633                 *spr            -> pointer to a glImage
01634  
01635 ******************************************************************************/
01636 void glSpriteStretchVertical( int x, int y, int height, const glImage *spr )    
01637 {       
01638         int hh = (spr->height/2);
01639 
01640         int x1 = x;
01641         int y1 = y;
01642         int x2 = x + spr->width;
01643         int y2 = y + height;
01644         
01645         float u_off = spr->u_off;
01646         float v_off = spr->v_off;
01647         
01648         float u_width = spr->u_width;
01649         float v_height = spr->v_height;
01650 
01651         float tv = v_height/2.0f;
01652                 
01653         if ( spr->textureID != gCurrentTexture )
01654     {
01655         glBindTexture( GL_TEXTURE_2D, spr->textureID );
01656         gCurrentTexture = spr->textureID;
01657     }
01658         
01659         // top
01660         int y21 = y1 + hh;
01661         
01662         glBegin( GL_QUADS );
01663         
01664                 glTexCoord2f( u_off, v_off );
01665                 glVertex2i( x1, y1 );
01666                 
01667                 glTexCoord2f( u_off, v_off + tv );
01668                 glVertex2i( x1, y21 );
01669                 
01670                 glTexCoord2f( u_off + u_width, v_off + tv );
01671                 glVertex2i( x2, y21 );
01672                 
01673                 glTexCoord2f( u_off + u_width, v_off );
01674                 glVertex2i( x2, y1 );
01675                 
01676         glEnd();
01677         
01678         // center
01679         int y11 = y + hh;
01680         y21 = y2 - hh - 1;
01681         
01682         glBegin( GL_QUADS );
01683         
01684                 glTexCoord2f( u_off, v_off + tv );
01685                 glVertex2i( x1,y11 );
01686                                 
01687                 glTexCoord2f( u_off, v_off + tv );
01688                 glVertex2i( x1,y21 );
01689                 
01690                 glTexCoord2f( u_off + u_width, v_off + tv );
01691                 glVertex2i( x2, y21 );
01692                 
01693                 glTexCoord2f( u_off + u_width, v_off + tv );
01694                 glVertex2i( x2, y11 );
01695                 
01696         glEnd();
01697         
01698         // bottom
01699         y11 = y2 - hh - 1;
01700         
01701         glBegin( GL_QUADS );
01702         
01703                 glTexCoord2f( u_off, v_off + tv );
01704                 glVertex2i( x1,y11 );
01705                 
01706                 glTexCoord2f( u_off, v_off + v_height );
01707                 glVertex2i( x1, y2 );
01708                 
01709                 glTexCoord2f( u_off + u_width, v_off + v_height );
01710                 glVertex2i( x2, y2 );
01711                 
01712                 glTexCoord2f( u_off + u_width, v_off + tv );
01713                 glVertex2i( x2, y11 );
01714                 
01715         glEnd();
01716         
01717 }
01718 
01719 
01720 /******************************************************************************
01721 
01722     Draws a sprite cleanly stretched horizontally and vertically
01723         Parameters:
01724                 x                       -> x1 position of the sprite
01725                 y                       -> y1 position of the sprite
01726                 flipmode        -> mode for flipping (see GL_FLIP_MODE enum)
01727                 *spr            -> pointer to a glImage
01728  
01729 ******************************************************************************/
01730 
01731 void glSpriteStretchHV( int x, int y, int length, int height, const glImage *spr )      
01732 {       
01733         
01734         int hw = (spr->width/2);
01735         int hh = (spr->height/2);
01736 
01737         int x1 = x;
01738         int y1 = y;
01739         int x2 = x + length;
01740         int y2 = y + height;
01741         
01742         float u_off = spr->u_off;
01743         float v_off = spr->v_off;
01744         
01745         float u_width = spr->u_width;
01746         float v_height = spr->v_height;
01747 
01748         float su = u_width/2.0f;
01749         float tv = v_height/2.0f;
01750                 
01751         if ( spr->textureID != gCurrentTexture )
01752     {
01753         glBindTexture( GL_TEXTURE_2D, spr->textureID );
01754         gCurrentTexture = spr->textureID;
01755     }
01756         
01757         
01758         // variables
01759         
01760         int xh1 = x1 + hw;
01761         int yh1 = y1 + hh;
01762         int xh2 = x2 - hw;
01763         int yh2 = y2 - hh;
01764         
01765         
01766         // top-left
01767         glBegin( GL_QUADS );
01768                 glTexCoord2f( u_off, v_off );
01769                 glVertex2i( x1, y1 );
01770                 
01771                 glTexCoord2f( u_off, v_off + tv );
01772                 glVertex2i( x1, yh1 );
01773                 
01774                 glTexCoord2f( u_off + su, v_off + tv );
01775                 glVertex2i( xh1, yh1 );
01776                 
01777                 glTexCoord2f( u_off + su, v_off );
01778                 glVertex2i( xh1, y1 );
01779         glEnd();
01780         
01781         // top-right
01782         glBegin( GL_QUADS );
01783                 glTexCoord2f( u_off + su, v_off );
01784                 glVertex2i( xh2, y1 );
01785                 
01786                 glTexCoord2f( u_off + su, v_off + tv );
01787                 glVertex2i( xh2, yh1 );
01788                 
01789                 glTexCoord2f( u_off + u_width, v_off + tv );
01790                 glVertex2i( x2, yh1 );
01791                 
01792                 glTexCoord2f( u_off + u_width, v_off );
01793                 glVertex2i( x2, y1 );
01794         glEnd();
01795 
01796         // bottom left
01797         glBegin( GL_QUADS );
01798                 glTexCoord2f( u_off, v_off + tv);
01799                 glVertex2i( x1, yh2 );
01800                 
01801                 glTexCoord2f( u_off, v_off + v_height );
01802                 glVertex2i( x1, y2 );
01803                 
01804                 glTexCoord2f( u_off + su, v_off + v_height );
01805                 glVertex2i( xh1, y2 );
01806                 
01807                 glTexCoord2f( u_off + su, v_off + tv );
01808                 glVertex2i( xh1, yh2 );
01809         glEnd();
01810         
01811         // bottom - right
01812         glBegin( GL_QUADS );
01813                 glTexCoord2f( u_off + su, v_off + tv );
01814                 glVertex2i( xh2,yh2 );
01815                 
01816                 glTexCoord2f( u_off + su, v_off + v_height );
01817                 glVertex2i( xh2, y2 );
01818                 
01819                 glTexCoord2f( u_off + u_width, v_off + v_height );
01820                 glVertex2i( x2, y2 );
01821                 
01822                 glTexCoord2f( u_off + u_width, v_off + tv );
01823                 glVertex2i( x2, yh2 );
01824         glEnd();
01825 
01826         // top-border
01827         glBegin( GL_QUADS );
01828                 glTexCoord2f( u_off + su, v_off );
01829                 glVertex2i( xh1,y1 );
01830                                 
01831                 glTexCoord2f( u_off + su, v_off + tv );
01832                 glVertex2i( xh1,yh1 );
01833                 
01834                 glTexCoord2f( u_off + su, v_off + tv );
01835                 glVertex2i( xh2, yh1 );
01836                 
01837                 glTexCoord2f( u_off + su, v_off );
01838                 glVertex2i( xh2, y1 );
01839         glEnd();
01840         
01841         // bottom-border
01842         glBegin( GL_QUADS );
01843                 glTexCoord2f( u_off + su, v_off + tv);
01844                 glVertex2i( xh1,yh2 );
01845                                 
01846                 glTexCoord2f( u_off + su, v_off + v_height );
01847                 glVertex2i( xh1,y2 );
01848                 
01849                 glTexCoord2f( u_off + su, v_off + v_height );
01850                 glVertex2i( xh2, y2 );
01851                 
01852                 glTexCoord2f( u_off + su, v_off + tv);
01853                 glVertex2i( xh2, yh2 );
01854         glEnd();
01855         
01856         // left-border
01857         glBegin( GL_QUADS );
01858                 glTexCoord2f( u_off, v_off + tv);
01859                 glVertex2i( x1,yh1 );
01860                                 
01861                 glTexCoord2f( u_off, v_off + tv );
01862                 glVertex2i( x1,yh2 );
01863                 
01864                 glTexCoord2f( u_off + su, v_off + tv );
01865                 glVertex2i( xh1, yh2 );
01866                 
01867                 glTexCoord2f( u_off + su, v_off + tv );
01868                 glVertex2i( xh1, yh1 );
01869         glEnd();
01870         
01871         // right-border
01872         glBegin( GL_QUADS );
01873                 glTexCoord2f( u_off + su, v_off + tv);
01874                 glVertex2i( xh2,yh1 );
01875                                 
01876                 glTexCoord2f( u_off + su, v_off + tv );
01877                 glVertex2i( xh2,yh2 );
01878                 
01879                 glTexCoord2f( u_off + u_width, v_off + tv );
01880                 glVertex2i( x2, yh2 );
01881                 
01882                 glTexCoord2f( u_off + u_width, v_off + tv );
01883                 glVertex2i( x2, yh1 );
01884         glEnd();
01885         
01886         // center
01887         glBegin( GL_QUADS );
01888         
01889                 glTexCoord2f( u_off + su, v_off + tv );
01890                 glVertex2i( xh1,yh1 );
01891                                 
01892                 glTexCoord2f( u_off + su, v_off + tv );
01893                 glVertex2i( xh1,yh2 );
01894                 
01895                 glTexCoord2f( u_off + su, v_off + tv );
01896                 glVertex2i( xh2, yh2 );
01897                 
01898                 glTexCoord2f( u_off + su, v_off + tv );
01899                 glVertex2i( xh2, yh1 );
01900                 
01901         glEnd();
01902         
01903         
01904                 
01905 }
01906 
01907 /******************************************************************************
01908 
01909 ******************************************************************************/
01910 
01911 void glPrint( int x, int y, const char *text, const GLuint color )
01912 {
01913     
01914 
01915         glDisable( GL_TEXTURE_2D );
01916         glColor4ubv( (GLubyte*)(&color) );
01917                 glPushAttrib( GL_LIST_BIT );
01918                         glRasterPos2i( x, y+10 );
01919                         glDisable( GL_TEXTURE_2D );
01920                         glListBase( gFontOffset );
01921                         glCallLists( strlen(text), GL_UNSIGNED_BYTE, text );
01922                 glPopAttrib();
01923         glEnable( GL_TEXTURE_2D );
01924         
01925 }
01926 
01927 /******************************************************************************
01928 
01929     Initializes our spriteset with Texture Packer generated UV coordinates
01930         Very safe and easy to use.
01931         Parameters:
01932        filename     -> name of the file to load as texture
01933        *sprite          -> pointer to an array of glImage
01934        width/height -> image dimensions
01935            numframes    -> number of frames in a spriteset (auto-generated by Texture Packer)
01936            *texcoords   -> Texture Packer auto-generated array of UV coords
01937            textureID    -> Texture handle returned by glGenTextures()
01938        filtemode    -> GL_NEAREST or GL_LINEAR
01939 
01940 ******************************************************************************/
01941 GLuint glLoadSpriteSet( const char *filename,
01942                         glImage *sprite,
01943                         const int width,
01944                         const int height,
01945                         const int numframes,
01946                         const unsigned int *texcoords,
01947                         const  GLuint filtermode )
01948 {
01949 
01950     int i;
01951     GLuint textureID;
01952 
01953     glGenTextures ( 1, &textureID );
01954     glBindTexture ( GL_TEXTURE_2D, textureID );
01955 
01956     LoadTexture( filename );
01957 
01958     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
01959     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
01960     glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filtermode );
01961     glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filtermode );
01962     glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
01963 
01964     glBindTexture( GL_TEXTURE_2D, 0 );
01965 
01966     // init sprites texture coords and texture ID
01967     for ( i = 0; i < numframes; i++)
01968     {
01969         int j = i * 4; // texcoords array is u_off, wid, hei
01970         sprite[i].textureID = textureID;
01971         sprite[i].width = texcoords[j+2];
01972         sprite[i].height = texcoords[j+3];
01973         sprite[i].u_off = texcoords[j] / (float)width;                          // set x-coord
01974         sprite[i].v_off = texcoords[j+1] / (float)height;                       // y-coord
01975         sprite[i].u_width = texcoords[j+2] / (float)width;                      // set x-coord
01976         sprite[i].v_height = texcoords[j+3] / (float)height;            // y-coord
01977 
01978     }
01979 
01980     return textureID;
01981 
01982 }
01983 
01984 
01985 /******************************************************************************
01986 
01987     Initializes our Tileset (like glInitSpriteset()) but without the use of
01988         Texture Packer auto-generated files.
01989         Very rigid and prone to human error.
01990         !!! Can ony be used for tilesets whose tiles are the same sizes!!!
01991         Parameters:
01992                 *sprite                 -> pointer to an array of glImage
01993                 tile_wid        -> width of each tile in the texture
01994                 tile_hei        -> height of each tile in the texture
01995                 bmp_wid         -> width of of the texture in VRAM
01996                 bmp_hei         -> height of of the texture in VRAM
01997             filtemode    -> GL_NEAREST or GL_LINEAR
01998         
01999 ******************************************************************************/
02000 GLuint  glLoadTileSet( const char *filename,
02001                                            glImage *sprite,
02002                                            const int tile_wid,
02003                                            const int tile_hei,
02004                                            const int bmp_wid,
02005                                            const int bmp_hei,
02006                                            const  GLuint filtermode     )
02007 {
02008 
02009 
02010     GLuint textureID;
02011 
02012     glGenTextures ( 1, &textureID );
02013     glBindTexture ( GL_TEXTURE_2D, textureID );
02014 
02015     LoadTexture( filename );
02016 
02017     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
02018     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
02019     glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filtermode );
02020     glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filtermode );
02021     glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
02022 
02023     glBindTexture( GL_TEXTURE_2D, 0 );
02024         
02025         int i = 0;
02026         int x, y;
02027         
02028         
02029         // init sprites texture coords and texture ID
02030         for( y = 0; y < (bmp_hei/tile_hei); y++ )
02031         {
02032                 for( x = 0; x < (bmp_wid/tile_wid); x++ ) 
02033                 {
02034                         sprite[i].width                         = tile_wid;
02035                         sprite[i].height                        = tile_hei;
02036                         sprite[i].u_off                         = (x*tile_wid)/(float)bmp_wid;
02037                         sprite[i].v_off                         = (y*tile_hei)/(float)bmp_hei; 
02038                         sprite[i].u_width                       = tile_wid/(float)bmp_wid;
02039                         sprite[i].v_height                      = tile_hei/(float)bmp_hei;
02040                         sprite[i].textureID             = textureID;
02041                         
02042                         i++;
02043                 }
02044         }
02045 
02046         return textureID;
02047 }
02048 
02049 GLuint glLoadSprite( const char *filename,
02050                      glImage *sprite,
02051                      const int width,
02052                      const int height,
02053                      const  GLuint filtermode )
02054 {
02055 
02056     GLuint textureID;
02057 
02058     glGenTextures ( 1, &textureID );
02059     glBindTexture ( GL_TEXTURE_2D, textureID );
02060 
02061     LoadTexture( filename );
02062 
02063     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
02064     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
02065     glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filtermode );
02066     glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filtermode );
02067     glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
02068 
02069     glBindTexture( GL_TEXTURE_2D, 0 );
02070 
02071     sprite->textureID = textureID;
02072     sprite->width = width;
02073     sprite->height = height;
02074     sprite->u_off = 0.0;                // set x-coord
02075     sprite->v_off = 0.0;                // y-coord
02076     sprite->u_width = 1.0;              // set x-coord
02077     sprite->v_height = 1.0;             // y-coord
02078 
02079 
02080     return textureID;
02081 
02082 }
02083 
02084 /******************************************************************************
02085 
02086 
02087 ******************************************************************************/
02088 void glGet( glImage *SpriteDest, const glImage *SpriteSource, int x1, int y1, int x2, int y2 )
02089 {
02090         
02091         int width = (x2 - x1 ) + 1;
02092         int height = (y2 - y1 ) + 1;
02093         float uoff = x1 / (float) SpriteSource->width;
02094         float voff = y1 / (float) SpriteSource->height;
02095         float uwidth = width / (float) SpriteSource->width;
02096         float vheight= height / (float) SpriteSource->height;
02097         
02098         SpriteDest->textureID = SpriteSource->textureID;
02099     SpriteDest->width = width;
02100     SpriteDest->height = height;
02101     SpriteDest->u_off = uoff;           // set x-coord
02102     SpriteDest->v_off = voff;           // y-coord
02103     SpriteDest->u_width = uwidth;               // set x-coord
02104     SpriteDest->v_height = vheight;             // y-coord
02105         
02106         
02107 }

Generated on Mon Feb 13 2012 15:16:03 for Easy GL2D Programmer's Reference by  doxygen 1.7.2